﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>检验要素数量统计看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .el-form-item__label {
      color: #fff;
    }

    .header-title {
      font-size: 24px;
    }

    .el-form-item {
      margin-bottom: 0 !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <!-- 看板标题组件 -->
      <vue2-board-header :title="title"></vue2-board-header>
      <!-- 查询条件 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" style="margin:5px;">
        <el-form-item label="主制分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择主制分厂" clearable filterable @change="handlerChange">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handlerBtnSearch">查询</el-button>
        </el-form-item>
      </el-form>

      <dv-border-box-11 title="今日统计">
        <div :style="{height: chartHeight + 'px',paddingTop:'40px'}" id="thisDay"></div>
      </dv-border-box-11>

      <dv-border-box-11 title="本月统计">
        <div :style="{height: chartHeight + 'px',paddingTop:'40px'}" id="thisMonth"></div>
      </dv-border-box-11>

      <dv-border-box-11 title="本年统计">
        <div :style="{height: chartHeight + 'px',paddingTop:'40px'}" id="thisYear"></div>
      </dv-border-box-11>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { getFactoryListByCode, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import Vue2BoardHeader from '../Scripts/components/Vue2BoardHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2BoardHeader },
      data: {
        loading: false,
        loadingText: '数据加载中...',
        title: '',
        queryInfo: {
          factoryid: '',
          factoryname: '',
          thisDay: [],
          thisMonth: [],
          thisYear: []
        },
        factoryList: [],
        userInfo: {},
        chartHeight: 360,
        chartRow: 3,
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' }
      },
      methods: {
        async getToday() {
          echarts.dispose(document.getElementById("thisDay"));
          let chart = echarts.init(document.getElementById('thisDay'));
          chart.showLoading(this.loadingConfig);
          const { data: { data, meta, total } } = await axios.post('../handler/board/CheckElementsCountDashBoard.ashx?action=getThisDay', {
            type: 'getToday',
            ...this.queryInfo,
            searchType: 'today'
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(document.getElementById("thisDay"));
          chart = echarts.init(document.getElementById('thisDay'));
          let arrPerson = [], arrQty = [];
          for (const i of data) {
            arrPerson.push(i.fullname);
            arrQty.push(i.qty);
          }

          let option = barOption();
          option.legend.data = ['数量'];//设置图例文字
          option.xAxis.data = arrPerson;//x轴数据
          option.yAxis[1].show = false;//隐藏第二y轴

          const { color, colorStops } = colorList.blue;
          option.series[0] = _.merge(option.series[0], {
            name: '数量', data: arrQty,
            label: { color: color },
            itemStyle: { color: { colorStops: colorStops } }
          });

          chart.setOption(option);
        },
        async getThisMonth() {
          echarts.dispose(document.getElementById("thisMonth"));
          let chart = echarts.init(document.getElementById('thisMonth'));
          chart.showLoading(this.loadingConfig);
          const { data: { data, meta, total } } = await axios.post('../handler/board/CheckElementsCountDashBoard.ashx?action=getThisMonth', {
            type: 'getThisMonth',
            ...this.queryInfo,
            searchType: 'thisMonth'
          })

          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(document.getElementById("thisMonth"));
          chart = echarts.init(document.getElementById('thisMonth'));

          let arrPerson = [], arrQty = [];
          for (const i of data) {
            arrPerson.push(i.fullname);
            arrQty.push(i.qty);
          }

          let option = barOption();
          option.legend.data = ['数量'];//设置图例文字
          option.xAxis.data = arrPerson;//x轴数据
          option.yAxis[1].show = false;//隐藏第二y轴

          option.series[0] = _.merge(option.series[0], {
            name: '数量',
            data: arrQty,
            type: 'line',
            symbolSize: 8,
            yAxisIndex: 1,
            label: { color: colorList.red.color },
            lineStyle: { width: 3, color: colorList.red.color },
            itemStyle: { color: { colorStops: colorList.red.colorStops } }
          });
          chart.setOption(option);
        },
        async getThisYear() {
          echarts.dispose(document.getElementById("thisYear"));
          let chart = echarts.init(document.getElementById('thisYear'));
          chart.showLoading(this.loadingConfig);
          const { data: { data, meta, total } } = await axios.post('../handler/board/CheckElementsCountDashBoard.ashx?action=getThisYear', {
            type: 'getThisYear',
            ...this.queryInfo,
            searchType: 'thisYear'
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(document.getElementById("thisYear"));
          chart = echarts.init(document.getElementById('thisYear'));

          let arrPerson = [], arrQty = [];
          for (const i of data) {
            arrPerson.push(i.fullname);
            arrQty.push(i.qty);
          }

          let option = barOption();
          option.legend.data = ['数量'];//设置图例文字
          option.xAxis.data = arrPerson;//x轴数据
          option.yAxis[1].show = false;//隐藏第二y轴

          const { color, colorStops } = colorList.blue;
          option.series[0] = _.merge(option.series[0], {
            name: '数量', data: arrQty,
            label: { color: color },
            itemStyle: { color: { colorStops: colorStops } }
          });

          chart.setOption(option);
        },
        handlerBtnSearch() {
          this.getToday()
          this.getThisMonth()
          this.getThisYear()
        },
        handlerChange() {
          this.queryInfo.factoryname = this.factoryList.filter(item => item.factoryid === this.queryInfo.factoryid)[0].factoryname;
          this.title = `${this.queryInfo.factoryname}检验要素数量统计看板`;
          document.title = this.title;
        }
      },
      async mounted() {
        const today = dayjs().format('YYYY-MM-DD');
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        const startOfThisYear = dayjs().startOf('year').format('YYYY-MM-DD');
        const endOfThisYear = dayjs().endOf('year').format('YYYY-MM-DD');
        this.queryInfo.thisDay = [today, today];
        this.queryInfo.thisMonth = [startOfThisMonth, endOfThisMonth];
        this.queryInfo.thisYear = [startOfThisYear, endOfThisYear];
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });
        this.factoryList = await getFactoryListByCode({ factoryCode: '601|607|609|600|608' });
        if (this.userInfo.factoryid && this.factoryList.some(item => item.factoryid === this.userInfo.factoryid)) {
          const { factoryid, factoryname } = this.userInfo;
          this.queryInfo.factoryid = factoryid;
          this.queryInfo.factoryname = factoryname;
        } else {
          this.queryInfo.factoryid = this.factoryList[0].factoryid;
          this.queryInfo.factoryname = this.factoryList[0].factoryname;
        }
        this.title = `${this.queryInfo.factoryname}检验要素数量统计看板`;
        document.title = this.title;
        this.getToday();
        this.getThisMonth();
        this.getThisYear();
      }
    })
  </script>
</body>

</html>